import request from '@/utils/request'

// 创建评价
export const createReview = (data) => {
  return request({
    url: '/foodReviews/rate',
    method: 'post',
    data
  });
};

// 获取评价详情
export const getReviewById = (id) => {
  return request({
    url: `/foodReviews/${id}`,
    method: 'get'
  })
}

// 删除评价
export const deleteReview = (id) => {
  return request({
    url: `/foodReviews/${id}`,
    method: 'delete'
  })
}

// 更新评价
export const updateReview = (data) => {
  return request({
    url: '/foodReviews',
    method: 'put',
    data: {
      foodId: data.foodId,
      userId: data.userId,
      businessId: data.businessId,
      rating: data.rating,
      comment: data.comment
    }
  })
}

// 获取商品评价列表
export const getFoodReviews = (foodId) => {
  return request({
    url: `/foodReviews/listFoodReviewsByFoodId/${foodId}`,
    method: 'get'
  })
}

// 获取用户评价列表
export const getUserReviews = (userId) => {
  return request({
    url: `/foodReviews/listFoodReviewsByUserId/${userId}`,
    method: 'get'
  })
}

// 获取商家评价列表
export const getBusinessReviews = (businessId) => {
  return request({
    url: `/foodReviews/listFoodReviewsByBusinessId/${businessId}`,
    method: 'get'
  })
}